var tl;
var eventSource;

function onLoad() {
	var eventCount = 0;
	var DefaultEvent = Timeline.DefaultEventSource.Event;
	Timeline.DefaultEventSource.Event = function(){
	  DefaultEvent.apply(this, arguments);
	  eventCount++;
				
	  var str = '';
	  for(var prop in this){
		var v = this[prop];
		if (v == null)
		  continue;
		if (v.constructor == Function)
		  continue;
		str = str + ', ' + prop + ':' + v;
	  }
	}
	Timeline.DefaultEventSource.Event.prototype = DefaultEvent.prototype;
	eventSource = new Timeline.DefaultEventSource();
    Timeline.loadJSON("/entry/json_timeline", function(http,url) {
  	  eventSource.loadJSON(http,url);
	  if (tl != null) 
	     tl.setDate(eventSource.getEarliestDate());
    });
	
	var bandInfos = [
    Timeline.createBandInfo({
		eventSource:    eventSource,
		// showEventText:  false,
        width:          "85%",
		trackHeight:	1.0,
		timeZone:		+9,
        intervalUnit:   Timeline.DateTime.DAY, 
        intervalPixels: 300
    }),
    Timeline.createBandInfo({
		eventSource:    eventSource,
		showEventText:  false,
        width:          "15%",
        intervalUnit:   Timeline.DateTime.HOUR, 
        intervalPixels: 70,
		timeZone:		+9
    }) ];
	bandInfos[0].syncWith = 1;
	bandInfos[0].highlight = true;
	/* bandInfos[1].eventPainter.setLayout(bandInfos[0].eventPainter.getLayout()); */
	tl = Timeline.create(document.getElementById("my-timeline"), bandInfos);
    document.getElementById('gmap').style.width = tl.getPixelLength() + 'px';
	
	showRankingData();
}

var resizeTimerID = null;
function onResize() {
    if (resizeTimerID == null) {
        resizeTimerID = window.setTimeout(function() {
            resizeTimerID = null;
            tl.layout();
        }, 500);
    }
}

function showRankingData(){
	new Ajax.Request("/entry/ranking", 
		{method: "get",onSuccess: 
		function(httpObj) {
			var contents = new Object();
			contents = httpObj.responseText;
			float_win = new Window({className: "mac_os_x", title: "Access Ranking", width:350, height:400, destroyOnClose: true, recenterAuto:false}); 
			float_win.getContent().update(contents); 
    		float_win.setLocation(100, 950);
    		float_win.show();}
		});
	}
